package com.bootdo.jiashan.service.impl;

import com.bootdo.common.utils.BeanCopierUtil;
import com.bootdo.common.utils.RejectUtil;
import com.bootdo.jiashan.model.SupplierModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.bootdo.jiashan.dao.SupplierDao;
import com.bootdo.jiashan.domain.SupplierDO;
import com.bootdo.jiashan.service.SupplierService;
import org.springframework.util.CollectionUtils;


@Service
public class SupplierServiceImpl implements SupplierService {
	@Autowired
	private SupplierDao supplierDao;
	
	@Override
	public SupplierDO get(Integer id){
		return supplierDao.get(id);
	}
	
	@Override
	public List<SupplierModel> list(Map<String, Object> map){
		List<SupplierModel> modelList = new ArrayList<>();
		List<SupplierDO> doList = supplierDao.list(map);
		if(!CollectionUtils.isEmpty(doList)){
			doList.forEach(supplierDO -> {
				SupplierModel model = new SupplierModel();
				BeanCopierUtil.copyProperties(supplierDO,model);
				modelList.add(model);
			});
		}
		return modelList;
	}
	
	@Override
	public int count(Map<String, Object> map){
		return supplierDao.count(map);
	}
	
	@Override
	public int save(SupplierDO supplier) throws IllegalAccessException {
		supplier.setCtime(System.currentTimeMillis());
		supplier.setUtime(0L);
		RejectUtil.nullToEmptyStrOr0(supplier);
		return supplierDao.save(supplier);
	}
	
	@Override
	public int update(SupplierDO supplier) throws IllegalAccessException {
		supplier.setUtime(System.currentTimeMillis());
		RejectUtil.nullToEmptyStrOr0(supplier);
		return supplierDao.update(supplier);
	}
	
	@Override
	public int remove(Integer id){
		return supplierDao.remove(id);
	}
	
	@Override
	public int batchRemove(Integer[] ids){
		return supplierDao.batchRemove(ids);
	}
	
}
